home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
081-090
/
amok81
/
m2
/
demos
/
txt
/
eyes.mod
next >
Wrap
Text File
|
1993-11-04
|
2KB
|
90 lines
MODULE Eyes; (* jr/30apr89, adapted to V4.0: bp/9/Dec/90 *)
(*$ LargeVars:=FALSE StackChk:=FALSE RangeChk:=FALSE OverflowChk:=FALSE
StackParms:=FALSE Volatile:=FALSE
*)
FROM SYSTEM IMPORT ADDRESS, ADR, FFP;
FROM ExecL IMPORT Forbid, GetMsg, Permit, ReplyMsg;
FROM GraphicsD IMPORT DrawModes, DrawModeSet, RastPortPtr;
FROM GraphicsL IMPORT DrawEllipse, SetAPen, SetDrMd, WaitTOF;
FROM IntuitionD IMPORT IDCMPFlags, IDCMPFlagSet, NewWindow, ScreenFlags,
ScreenFlagSet, WindowFlags, WindowFlagSet, WindowPtr;
FROM IntuitionL IMPORT CloseWindow, OpenWindow;
FROM MathTrans IMPORT Sqrt;
VAR
u: WindowPtr;
rp: RastPortPtr;
nw := NewWindow{
title: ADR('EYES'),
leftEdge: 30, topEdge: 70,
width: 120, height: 35,
detailPen: 2, blockPen: 1,
idcmpFlags: IDCMPFlagSet{closeWindow},
flags: WindowFlagSet{windowDrag, windowDepth, windowClose},
type: ScreenFlagSet{wbenchScreen},
firstGadget: NIL,
checkMark: NIL,
screen: NIL,
bitMap: NIL
};
PROCEDURE InitWindow;
BEGIN
u:=OpenWindow(nw);
IF u=NIL THEN HALT END;
rp:=u^.rPort;
SetDrMd(rp, DrawModeSet{complement})
END InitWindow;
VAR
pup: ARRAY [0..1] OF RECORD
cx, cy, (* center of eye *)
x, y, (* center of pupil *)
oldX, oldY: INTEGER (* old position of pupil *)
END;
PROCEDURE DrawPupil(i: INTEGER);
VAR
dx, dy, l: FFP;
mx, my: INTEGER; (* mouse coordinates *)
BEGIN
mx:=u^.mouseX; my:=u^.mouseY;
WITH pup[i] DO
dx:=FFP(mx-cx)*0.5;
dy:=FFP(my-cy);
l:=Sqrt(dx*dx + dy*dy);
IF l<=5.0 THEN (* inside eye *)
x:=mx; y:=my;
ELSE
l:=5.0/l; x:=cx+INTEGER(2.0*l*dx); y:=cy+INTEGER(l*dy)
END;
IF (oldX#x) OR (oldY#y) THEN
SetAPen(rp,1);
DrawEllipse(rp, oldX, oldY, 10, 5);
SetAPen(rp,2);
DrawEllipse(rp, x, y, 10, 5);
oldX:=x; oldY:=y;
END;
END (* WITH *)
END DrawPupil;
VAR
msg: ADDRESS;
BEGIN
InitWindow;
DrawEllipse(rp, 30, 22, 20, 10);
DrawEllipse(rp, 90, 22, 20, 10);
pup[0].cx:=30; pup[0].cy:=22;
pup[1].cx:=90; pup[1].cy:=22;
LOOP
DrawPupil(0); DrawPupil(1);
msg:=GetMsg(u^.userPort); IF msg#NIL THEN EXIT END;
WaitTOF;
END;
ReplyMsg(msg)
CLOSE
IF u#NIL THEN CloseWindow(u); u:=NIL END;
END Eyes.mod